home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / ctools / print.c < prev   
Text File  |  1985-12-24  |  6KB  |  217 lines

  1.  
  2. /* --------------------------------------------------- */
  3. /*   PRINT - Print a file with header to the printer   */
  4. /*    M. Burton      04 July 1983                      */
  5. /*   Written in Computer Innovations C86               */
  6. /* --------------------------------------------------- */
  7. /*    Syntax:                                          */
  8. /*                                                     */
  9. /*   PRINT filename.typ - Print a file with line       */
  10. /*           numbers.                                  */
  11. /*   PRINT filename.typ /N - Print a file without      */
  12. /*           line numbers.                             */
  13. /* --------------------------------------------------- */
  14.  
  15. #include "stdio.h"
  16.  
  17. struct regval       /* Register structure for INT      */
  18. {
  19.       int ax,bx,cx,dx,si,di,ds,es;
  20. }
  21. struct regval srv, rrv, trv, brv;
  22. int mo, dy, yr;
  23. int hr, mn, sc, hn;
  24. char strng[256];
  25.  
  26. main(argc,argv)
  27.       int argc;      /* Number of args in cmd line     */
  28.       char *argv[];  /* Args in cmd line               */
  29. {
  30.       int *fd;       /* File stream pointer            */
  31.       int *cd;       /* Printer stream pointer         */
  32.       char *sp;      /* filename.typ pointer           */
  33.       int c;         /* Loop variable                  */
  34.       int lineno=1;  /* Line counter                   */
  35.       int pline=1;   /* Line on page counter           */
  36.       int page=1;    /* Page counter                   */
  37.       char s[232];   /* Line buffer                    */
  38.  
  39.       srv.ax = (0x2c << 8);
  40.       sysint(0x21,&srv,&brv); /* Get the time          */
  41.  
  42.       if (argc == 1)
  43.       {
  44.           fputs("Proper syntax: PRINT filename.typ </N>\007\n",stdout);
  45.           goto abort;
  46.       }
  47.  
  48.       sp = argv[1];
  49.       while ((*sp = toupper(*sp)) != EOS) sp++;
  50.       fd = fopen(argv[1],"r");
  51.       if (fd == 0)
  52.       {
  53.           fputs(argv[1],stdout);
  54.           fputs(" not found\007\n");
  55.           goto abort;
  56.       }
  57.  
  58.       cd = fopen("PRN:","w");
  59.       if (cd == 0)
  60.       {
  61.           fputs("Printer offline\007\n");
  62.           goto abort;
  63.       }
  64.  
  65.       c = 1;
  66.       prthdr(page,cd,argv[1]);
  67.       while (c != EOS)
  68.       {
  69.           pline = 2;
  70.           while (pline < 57)
  71.           {
  72.                 c = fgets(s,232,fd);
  73.                 if (c == EOS) goto quit;
  74.                 if (argc == 3)
  75.                 {
  76.                    if (strncmp(argv[2],"/n",2) == 0 || strncmp(argv[2],"/N",2) == 0)
  77.                    {
  78.                        fputs(s,cd);
  79.                    }
  80.                 }
  81.                 else
  82.                 {
  83.                    iprnt(lineno,7," ");
  84.                    fputs(strng,cd);
  85.                    fputs("  ",cd);
  86.                    fputs(s,cd);
  87.                 }
  88.                 lineno++;
  89.                 pline++;
  90.           }
  91.           page++;
  92.           fputs("\n\014",cd);
  93.           prthdr(page,cd,argv[1]);
  94.       }
  95. quit:
  96.       fputs("  \n\014",cd);
  97.       srv.ax = (0x2c << 8);
  98.       sysint(0x21,&srv,&trv);       /* Get end time      */
  99.       hr = (trv.cx >> 8) - (brv.cx >> 8);
  100.       if((mn = (trv.cx & 0xff) - (brv.cx & 0xff)) < 0)
  101.       {
  102.           hr--;
  103.           mn = mn + 60;
  104.       }
  105.       if((sc = (trv.dx >> 8) - (brv.dx >> 8)) < 0)
  106.       {
  107.           mn--;
  108.           sc = sc + 60;
  109.           if (mn < 0)
  110.           {
  111.                 hr--;
  112.                 mn = mn + 60;
  113.           }
  114.       }
  115.       fputs("Finished printing '",stdout);
  116.       fputs(argv[1],stdout);
  117.       fputs("'; ",stdout);
  118.       iprnt(--lineno,5," ");
  119.       fputs(strng,stdout);
  120.       fputs(" lines,",stdout);
  121.       iprnt(page,5," ");
  122.       fputs(strng,stdout);
  123.       fputs(" pages.\n",stdout);
  124.       fputs("Total print time ",stdout);
  125.       iprnt(hr,2,"0");
  126.       fputs(strng,stdout);
  127.       fputs(":",stdout);
  128.       iprnt(mn,2,"0");
  129.       fputs(strng,stdout);
  130.       fputs(":",stdout);
  131.       iprnt(sc,2,"0");
  132.       fputs(strng,stdout);
  133.       fputs("\n",stdout);
  134.       fclose(fd);
  135.       fclose(cd);
  136. abort:      ;       /* Dummy line             */
  137. }
  138.  
  139. prthdr(p,cc,aa)       /* Print the page header      */
  140.       int p, cc, *aa;
  141. {
  142.       srv.ax = (0x2a << 8);
  143.       sysint(0x21,&srv,&rrv);
  144.       mo = (rrv.dx >> 8);
  145.       dy = (rrv.dx & 0xff);
  146.       yr = rrv.cx;
  147.       srv.ax = (0x2c << 8);
  148.       sysint(0x21,&srv,&trv);
  149.       hr = (trv.cx >> 8);
  150.       mn = (trv.cx & 0xff);
  151.       sc = (trv.dx >> 8);
  152.       hn = (trv.dx & 0xff);
  153.       fputs("Listing of ",cc);
  154.       fputs(aa,cc);
  155.       fputs("     ",cc);
  156.       iprnt(mo,2,"0");
  157.       fputs(strng,cc);
  158.       fputs("-",cc);
  159.       iprnt(dy,2,"0");
  160.       fputs(strng,cc);
  161.       fputs("-",cc);
  162.       iprnt(yr,4,"0");
  163.       fputs(strng,cc);
  164.       fputs("     ",cc);
  165.       iprnt(hr,2,"0");
  166.       fputs(strng,cc);
  167.       fputs(":",cc);
  168.       iprnt(mn,2,"0");
  169.       fputs(strng,cc);
  170.       fputs(":",cc);
  171.       iprnt(sc,2,"0");
  172.       fputs(strng,cc);
  173.       fputs(".",cc);
  174.       iprnt(hn,2,"0");
  175.       fputs(strng,cc);
  176.       fputs("                Page ",cc);
  177.       iprnt(p,3," ");
  178.       fputs(strng,cc);
  179.       fputs("\n\n",cc);
  180. }
  181.  
  182. iprnt(n,l,f)      /* Print a decimal number */
  183.       int n,l;
  184.       char *f;
  185. {
  186.       int i,j,sign,c;
  187.  
  188.       if ((sign = n) < 0) n = -n;
  189.       i = 0;
  190.       do strng[i++] = n % 10 + '0';
  191.       while ((n /= 10) > 0);
  192.       if (sign < 0) strng[i++] = '-';
  193.       strng[i] = 0;
  194.       while (strlen(strng) < l)
  195.           {
  196.               strng[i++] = *f;
  197.               strng[i] = 0;
  198.           }
  199.       for (i=0, j=strlen(strng)-1; i<j; i++, j--)
  200.       {
  201.           c = strng[i];
  202.           strng[i] = strng[j];
  203.           strng[j] = c;
  204.       }
  205. }
  206. =x│ε)dƒ┌Pï╞╚▄▐@Cfwî₧á▒∞'*eá█Qî╟!\^t}╞▌µΦ².Nbkì│╩╙╒⌠<S\^lîñ¡├ßε    >    ^    q    ╟    ▌    
  207. 
  208. +
  209. A
  210. T
  211. }
  212. ó
  213. τ
  214. ·
  215.  / < O n Æ ¢ ó ┐ ▄  D | à û » ╕ ∞ ⌡ 6CZyåÅ╗┘⌡/Oiàº╤Θ7Smàí╝╧ΓQhkêº┬▀≤/Jgéƒ┐╘ε4LdzƬ─▄⌠
  216. ":PhÇû«╞≡8;=m}ìɺ⌐╠┌ DYzçº─╤&F_hk═@DDDN